/**
 * Created by john on 2018/3/28.
 */
var express = require('express');
var router = express.Router();
var qs  = require("qs");
var CONF = require("../config/conf");
var CODE = require("../config/code");
var request = require("request");

/*pc端页面得路由*/
/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('index', { title: 'Express' });
});


//来自sso的通知，退出登录
router.post('/sso/loginout', function(req, res, next) {
    var sessionid = req.body.sessionid;
    req.session.destroy(sessionid);
    res.send("ok");
});
//自己的页面退出登录
router.post('/api/loginout', function(req, res, next) {
   var userinfo = req.session.userinfo;
    if(userinfo){
        var _token = userinfo._token;
        request({
            timeout:5000,    // 设置超时
            method:'POST',    //请求方式
            url:CONF.ssoLoginOut, //url
            form:{
                _token:_token,
                _app:CONF.appName
            }
        },function (error, response, body) {

        });
    }
    req.session.userinfo = '';
    res.send(CODE.success);
});


module.exports = router;
